package com.cultusoft.groovin.plugins.project;

import com.cultusoft.groovin.plugins.build.Project;
import com.cultusoft.groovin.plugins.build.ProjectBuilder;
import com.cultusoft.groovin.plugins.build.ProjectPackager
import com.cultusoft.groovin.plugins.build.WarProjectPackager
import com.cultusoft.groovin.plugins.deploy.WarProjectDeployer
import com.cultusoft.groovin.configuration.Configuration
import com.cultusoft.groovin.plugins.build.WarProject;
import com.cultusoft.groovin.plugins.clean.ProjectCleaner
import com.cultusoft.groovin.plugins.eclipse.EclipsePropertyKeeper

class ProjectFactory {

    private static List projects = new ArrayList();
    
    public static List getProjects() {
        return projects;
    }

    
    public static Project createProject(args) {

        def projectDirectory = new ProjectDirectoryFinder().getProjectDirectory(args.dirName);
        def project =  new Project(name:args.dirName, directory: projectDirectory)
        project.builder = new ProjectBuilder(project:project)
        project.packager = new ProjectPackager(project:project)
        project.tester = new ProjectTester(project:project)
        project.deployer = new NullProjectDeployer()
        project.cleaner = new ProjectCleaner(project:project)
    
        EclipsePropertyKeeper.addProperty(project)
        projects.add(project)
        
        return project
    }

    public static Project createTestProject(args) {
        def projectDirectory = new ProjectDirectoryFinder().getProjectDirectory(args.dirName);
        def project =  new TestProject(name:args.dirName, directory: projectDirectory)
        project.builder = new ProjectBuilder(compilingDestination:"test-classes", project:project)
        project.packager = new ProjectPackager(project:project)
        project.tester = new ProjectTester(project:project)
        project.deployer = new NullProjectDeployer()
        project.sourceDirectoriesPaths = [projectDirectory + "/src/java", projectDirectory + "/src/test"] as List
        project.cleaner = new ProjectCleaner(project:project)
        projects.add(project)
        
        return project   
    }
    public static Project createWarProject(args) {
        def projectDirectory = new ProjectDirectoryFinder().getProjectDirectory(args.dirName);
        def project = new WarProject(name:args.dirName, directory: projectDirectory)
        project.builder = new ProjectBuilder(project:project)
        project.packager = new WarProjectPackager(project:project)
        project.tester = new NullProjectTester()
        project.deployer = new WarProjectDeployer(project:project)
        project.cleaner = new ProjectCleaner(project:project)
        projects.add(project)
        return project
        
    }
    
    public static Project createLibraryProject(args){
        LibraryProject project = new LibraryProject(group:args.group, id:args.id, version:args.version)
        project.builder = new NullProjectBuilder()
        project.packager = new NullProjectPackager()
        project.tester = new NullProjectTester()
        project.deployer = new NullProjectDeployer()
        project.cleaner = new NullProjectCleaner()
        return project
    }
   
}
